﻿/*
 *  Source code courtesy of the desktopWeb.CodePlex.com community project. See MS-PL license on Codeplex.com. 
 *  This is beta code not intended for a production application.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
using System.Windows.Forms;
using MyData.ExtensionMethods;
using System.Windows.Forms.Integration;
using MyData.WordAddIn.CustomTaskPanes;

namespace MyData.WordAddIn
{
    public partial class ThisAddIn
    {
      Microsoft.Office.Tools.CustomTaskPane ctp;
      private void ThisAddIn_Startup(object sender, System.EventArgs e)
      {
        UserControl taskPaneUserControl = new UserControl();
        NotesUserControl taskPaneXAMLControl = new NotesUserControl();
        ctp = CustomTaskPanes.Add(taskPaneUserControl, "Notes");

        taskPaneXAMLControl.HostTaskPane = ctp;

        taskPaneUserControl.Controls.Add(new ElementHost { Child = taskPaneXAMLControl, Dock = DockStyle.Fill });

        ctp.Visible = true;
        ctp.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
        ctp.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
        ctp.Width = 250;
        //taskPane
      }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }

    //Show form with Word as parent
    public class MyWin32Window : IWin32Window
    {
      private IntPtr _hwnd;

      public MyWin32Window(IntPtr handle)
      {
        _hwnd = handle;
      }

      public IntPtr Handle
      {
        get
        {
          return _hwnd;
        }
      }
    }
}
